package FenxiaoService

import (
	"context"
	toolsDb "gdshop-back-end-go/common/db"
	"gdshop-back-end-go/common/entity"
	"github.com/gogf/gf/frame/g"
)

// GetGoodsLevel 获取指定商品的分销设置数据
func GetGoodsLevel(ctx context.Context, goodsId, levelId int) (*entity.FenxiaoGoodsLevel, error) {
	var fglModel *entity.FenxiaoGoodsLevel
	err := toolsDb.GetUnSafaTable(ctx, "fenxiao_goods").As("fg").
		LeftJoin("fenxiao_goods_level fgl", "fgl.fenxiao_goods_id = fg.id").Fields("fgl.*").
		Where(g.Map{
			"fg.goods_id":  goodsId,
			"fg.status":    1,
			"fgl.level_id": levelId,
		}).Scan(&fglModel)

	if err != nil {
		return nil, err
	}

	return fglModel, nil
}
